package com.jackrain.nea.fc.cp.mapper;

import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 店仓接口-服务开发
 * Mapper
 *
 * @author WSL
 * @create 2017/10/23
 */
@Mapper
public interface ViewCstoreMapper {
    class SelectPro
    {
        public String selectProvider(Map map)
        {
            return new SQL()
            {
                {
                    /*CP_C_STOREORG_ID1,CP_C_STOREORG_ID2,CP_C_STOREORG_ID3,CP_C_STOREORG_ID4,CP_C_STOREORG_ID5,
                    CP_C_STOREORG_ID6,CP_C_STOREORG_ID7,CP_C_STOREORG_ID8,CP_C_STOREORG_ID9,CP_C_STOREORG_ID10*/
                    SELECT("ECODE,CP_C_DISTRIB_ID,STORECATE,ENAME,CP_C_CITY_ID," +
                            "SALECATE,PRORATION,ISOUT,ISRECEPT,ISUSEPOS,ISNEGATIVE,ISACTIVE,RESEVER,CONTACTER,MOBIL,PHONE,FAX,POST,MARKETRATE,MRENT," +
                            "AREAS,IMAGELEVEL,DATEEND,DATEBEGIN,ISWEEKADD,RECYCLE,WEIGHT,PREINDAYS,ARRIVETIME,MODIFIERID,MODIFIEDDATE,ADDRESS,WEAADDRESS," +
                            "LOGISTICS,STORETYPE,CP_C_EXPCOMPANY_ID,GROUPID,REMARK,LOCATION,SALETYPE,DATEOPEN,SALEAREAS,PROCOE,AREATYPE,RETCYCLE,RETPREDAYS," +
                            "BAGTYPE,SETTLERATE,PRODUCTER,BIGMANAGER,BUSSTATE,PREFER,RECYCLE_WH_ID,CLOSEDATE,ORUNIFY,SEABATCH,STORENATURE,RET_WH_ID,WEPAY_ID," +
                            "ALIPAY_ID,PLAN_CHECK_DATE,TXTDIM3,NUMDIM2,TXTDIM2,NUMDIM1,DECDIM1,CP_C_STOREORG_ID,DATEINV");
                    FROM("CP_C_STORE");
                    Object[] list = (Object[]) map.get("list");
                    StringBuilder sb = new StringBuilder("(");
                    for (Object num : list) {
                        sb.append(num).append(",");
                    }
                    sb.deleteCharAt(sb.length()-1).append(")");
                    WHERE("ID IN "+sb.toString());
                }
            } .toString();
        }
    }

    /**
     * 根据param查询条件 查询【供应商档案】表
     * @param param
     * @return String
     */
    @SelectProvider(type = SelectPro.class, method = "selectProvider")
    List<HashMap> selectProvider(@Param("list") Object[] param);

    /**
     * 查询【店仓组织】ECODE,ENAME
     * @param id
     * @return String
     */
    @Select("SELECT ECODE,ENAME,CP_C_STOREORG_LEVEL_ID,CP_C_ORGUP_ID FROM CP_C_STOREORG WHERE ID = #{id}")
    JSONObject selStoreorgEcode(Long id);

    /**
     * 查询【店仓属性值】ECODE
     * @param id
     * @return String
     */
    @Select("SELECT ECODE FROM CP_C_STOREDIM_ITEM WHERE ID = #{id}")
    String selStoredimItemEcode(Long id);

    /**
     * 查询【店仓属性值】ENAME
     * @param id
     * @return
     */
    @Select("SELECT ENAME FROM CP_C_STOREDIM_ITEM WHERE ID = #{id}")
    String selStoredimItemEname(Long id);

    /**
     * 查询【省市区】ECODE
     * @param id
     * @return String
     */
    @Select("SELECT ECODE FROM CP_C_REGION WHERE ID = #{id}")
    String selCityEcode(Long id);

    /**
     * 查询【用户】ECODE
     * @param id
     * @return String
     */
    @Select("SELECT ENAME FROM USERS WHERE ID = #{id}")
    String selUsersEname(Long id);

    /**
     * 查询【快递公司】ECODE
     * @param id
     * @return String
     */
    @Select("SELECT ECODE FROM CP_C_EXPCOMPANY WHERE ID = #{id}")
    String selExpcompanyEcode(Long id);

    /**
     * 查询【人员档案】ECODE
     * @param id
     * @return String
     */
    @Select("SELECT ECODE,ENAME FROM CP_C_EMP WHERE ID = #{id}")
    HashMap selEmpEcodeEname(Long id);

    /**
     * 查询【店仓档案】ECODE
     * @param id
     * @return String
     */
    @Select("SELECT ECODE FROM CP_C_STORE WHERE ID = #{id}")
    String selStoreEcode(Long id);

    /**
     * 查询【移动支付账号表】ECODE
     * @param id
     * @return
     */
    @Select("SELECT ECODE FROM CP_C_MPAYACC WHERE ID = #{id}")
    String selMpayaccEcode(Long id);

    /**
     * 查询【销售区域层级】
     * @param id
     * @return
     */
    @Select("SELECT STOREORG_LEVEL FROM CP_C_STOREORG_LEVEL WHERE ID = #{id}")
    Integer selStoreOrgLevel(Long id);

}
